
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: EntityModel.java 314 2010-02-10 18:52:16Z archie.cobbs $
 */

package org.dellroad.sidekar.schema.model;

/**
 * Deep copies {@link FieldModel} objects.
 */
class FieldDeepCopier implements FieldModelSwitch<FieldModel> {

    private final SchemaModel schemaModel;

    public FieldDeepCopier() {
        this(null);
    }

    public FieldDeepCopier(SchemaModel schemaModel) {
        this.schemaModel = schemaModel;
    }

    @Override
    public ReferenceFieldModel caseReferenceFieldModel(ReferenceFieldModel fieldModel) {
        return new ReferenceFieldModel(fieldModel, this.schemaModel);
    }

    @Override
    public SetFieldModel caseSetFieldModel(SetFieldModel fieldModel) {
        return new SetFieldModel(fieldModel, this.schemaModel);
    }

    @Override
    public MapFieldModel caseMapFieldModel(MapFieldModel fieldModel) {
        return new MapFieldModel(fieldModel, this.schemaModel);
    }

    @Override
    public ListFieldModel caseListFieldModel(ListFieldModel fieldModel) {
        return new ListFieldModel(fieldModel, this.schemaModel);
    }

    @Override
    public StringFieldModel caseStringFieldModel(StringFieldModel fieldModel) {
        return new StringFieldModel(fieldModel);
    }

    @Override
    public DateFieldModel caseDateFieldModel(DateFieldModel fieldModel) {
        return new DateFieldModel(fieldModel);
    }

    @Override
    public BigIntegerFieldModel caseBigIntegerFieldModel(BigIntegerFieldModel fieldModel) {
        return new BigIntegerFieldModel(fieldModel);
    }

    @Override
    public ArrayFieldModel caseArrayFieldModel(ArrayFieldModel fieldModel) {
        return new ArrayFieldModel(fieldModel);
    }

    @Override
    public BooleanFieldModel caseBooleanFieldModel(BooleanFieldModel fieldModel) {
        return new BooleanFieldModel(fieldModel);
    }

    @Override
    public ByteFieldModel caseByteFieldModel(ByteFieldModel fieldModel) {
        return new ByteFieldModel(fieldModel);
    }

    @Override
    public CharacterFieldModel caseCharacterFieldModel(CharacterFieldModel fieldModel) {
        return new CharacterFieldModel(fieldModel);
    }

    @Override
    public ShortFieldModel caseShortFieldModel(ShortFieldModel fieldModel) {
        return new ShortFieldModel(fieldModel);
    }

    @Override
    public IntegerFieldModel caseIntegerFieldModel(IntegerFieldModel fieldModel) {
        return new IntegerFieldModel(fieldModel);
    }

    @Override
    public FloatFieldModel caseFloatFieldModel(FloatFieldModel fieldModel) {
        return new FloatFieldModel(fieldModel);
    }

    @Override
    public DoubleFieldModel caseDoubleFieldModel(DoubleFieldModel fieldModel) {
        return new DoubleFieldModel(fieldModel);
    }

    @Override
    public LongFieldModel caseLongFieldModel(LongFieldModel fieldModel) {
        return new LongFieldModel(fieldModel);
    }
   
    @SuppressWarnings("unchecked")
    public static <T extends FieldModel> T copy(T fieldModel, SchemaModel schemaModel) {
        return (T)fieldModel.visit(new FieldDeepCopier(schemaModel));
    }
}

